package net.ainom.scarab.xmlrpc;

import java.io.File;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.tmatesoft.svn.core.internal.io.dav.DAVRepositoryFactory;
import org.tmatesoft.svn.core.internal.io.fs.FSRepositoryFactory;
import org.tmatesoft.svn.core.internal.io.svn.SVNRepositoryFactoryImpl;

public abstract class AbstractScarabIssueTrackerIntegration implements Runnable {
    protected Map          userIdMapping;
    protected URL          issueTrackingActionUrl;
    protected List         filter = new ArrayList();
    protected File         repo;
    protected long         rev;
    protected String       username = "";
    protected String       password = "";

    private static Boolean initialized;

    private static void setupLibrary() {
        /*
         * for DAV (over http and https)
         */
        DAVRepositoryFactory.setup();
        /*
         * for SVN (over svn and svn+ssh)
         */
        SVNRepositoryFactoryImpl.setup();

        FSRepositoryFactory.setup();
    }

    public AbstractScarabIssueTrackerIntegration() {
        super();
        synchronized (initialized) {
            if (initialized == null) {
                initialized = Boolean.TRUE;
                AbstractScarabIssueTrackerIntegration.setupLibrary();
            }
        }
    }

    public void addFilter(Filter filter) {
        this.filter.add(filter);
    }

    public void setIssueTrackingActionUrl(URL issueTrackingActionUrl) {
        this.issueTrackingActionUrl = issueTrackingActionUrl;
    }

    public void setRepo(File repo) {
        this.repo = repo;
    }

    public void setRev(long rev) {
        this.rev = rev;
    }

    public void setUserIdMapping(Map userIdMapping) {
        this.userIdMapping = userIdMapping;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public void setPassword(String password) {
        this.password = password;
    }
}
